package com.arron.state.study1;

public class Account {
    private double balance;
    private String owner;
    private AccountState state;

    public Account(double balance, String owner) {
        this.state = new NormalState(this);
        this.balance = balance;
        this.owner = owner;
        System.out.println(owner + "开户，初始金额为" + balance);
    }

    public double getBalance() {
        return balance;
    }

    public void setBalance(double balance) {
        this.balance = balance;
    }

    public void setState(AccountState state) {
        this.state = state;
    }

    //存款
    public void deposit(double amount){
        System.out.println(this.owner +"存款 "+amount);
        this.state.deposit(amount);
        System.out.println("现在余额为" + this.balance);
        System.out.println("状态"+this.state.getClass().getName());
        this.computerInterest();
        System.out.println("----------------------------------------");
    }
    //取款
    public void withdraw(double amount){
        System.out.println(this.owner +"取款 "+amount);
        this.state.withdraw(amount);
        System.out.println("现在余额为" + this.balance);
        System.out.println("状态"+this.state.getClass().getName());
        this.computerInterest();
        System.out.println("----------------------------------------");
    }
    //计算利息
    public void computerInterest(){
        this.state.computerInterest();
    }
}
